package com.zq.order.controller;


import com.github.pagehelper.PageInfo;
import com.zq.common.util.Result;
import com.zq.order.dao.dto.OrderStatisticsDto;
import com.zq.order.dao.entity.OrderInfo;
import com.zq.order.dao.vo.OrderListVo;
import com.zq.order.dao.vo.OrderStatisticsVo;
import com.zq.order.service.IOrderInfoService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2025-05-20
 */
@RestController
@RequestMapping("/order/order-info")
public class OrderInfoController {

    @Resource
    private IOrderInfoService orderInfoService;

    @GetMapping("/getOrderStatisticsData")
    public Result<OrderStatisticsVo> getOrderStatisticsData
            (OrderStatisticsDto orderStatisticsDto) {
        OrderStatisticsVo orderStatisticsVo = orderInfoService.
                getOrderStatisticsData(orderStatisticsDto) ;
        return Result.successData(orderStatisticsVo) ;
    }
    @GetMapping("/getPage/{page}/{limit}")
    public Result< PageInfo<OrderListVo>> getPage(@PathVariable Integer page,
                                  @PathVariable Integer limit,
                                  @RequestParam("consigneeName")String consigneeName) {
 PageInfo<OrderListVo> pageInfo= orderInfoService.getPages(page, limit, consigneeName) ;
        return Result.successData(pageInfo) ;
    }

//新增订单
    @PostMapping("/save")
    public Result<String> save(@RequestBody OrderListVo orderListVo) {
        orderInfoService.saveOrder(orderListVo) ;
        return Result.success() ;
    }
//修改订单
    @PutMapping("/update")
    public Result<String> update(@RequestBody OrderListVo orderListVo) {
        orderInfoService.updateOrder(orderListVo) ;
        return Result.success() ;
    }
//    删除订单
    @DeleteMapping("/deleteById/{id}")
    public Result<String> delete(@PathVariable Long id) {
        orderInfoService.deleteOrder(id) ;
        return Result.success() ;
    }
//获取用户的所有订单
    @GetMapping("getPageList/{page}/{limit}")
public Result<PageInfo<OrderInfo>> getPages(@PathVariable Integer page,
                                            @PathVariable Integer limit,
                                            @RequestParam(value = "product",required = false)String productName,
                                            @RequestHeader("userToken")String userToken) {
PageInfo<OrderInfo> pageInfo = orderInfoService.getPagesByproductName(page, limit,productName,userToken);
        return Result.successData(pageInfo);
    }



}
